package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo1 {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("李");
        c.add("某");
        c.add("好");
        c.add("帅");

        String a = "帅";
        System.out.println("集合的大小:"+c.size());
        System.out.println("集合是否为空:"+c.isEmpty());
        boolean d = c.contains(a);
        System.out.println(d);

        //c.remove(a);
        //System.out.println(c);


        Collection<String> c1 = new ArrayList<>();
        c1.add("黄");
        c1.add("某");
        c1.add("也");
        c1.add("帅");

        c.addAll(c1);
        System.out.println(c);
        System.out.println(c1);

        c.retainAll(c1);
        System.out.println(c);
        System.out.println(c1);

        /*
        c.removeAll(c1);
        System.out.println(c);
        System.out.println(c1);

         */

        Iterator<String> it = c.iterator();
        while (it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }
        for (String s : c) {
            System.out.println(s);
        }






    }
}
